﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors {
    import flash.events.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;

    public class BabyVO extends AbstractActorVO implements IMoving, ISpeaking, ITicking, IBaby, IHugging {

        private var _treatments:Array;
        private var _huged:Boolean;
        private var _diseaseId:int;
        private var _diseaseName:String;
        private var _diseaseType:String;
        private var _dismissed:Boolean;
        private var _durationType:String;
        private var _isNewDisease:Boolean;
        private var _lastFinalizedTreatment:ITreatment;
        private var _petDisease:String;
        private var _poked:Boolean;
        private var _blockedAt:int;
        private var _pendingHugCalls:int;
        private var _blockedIn:int;
        private var _isBlocked:Boolean;
        private var _time:Number;
        private var _animationState:String;// = "still"
        private var _speechBubbleVisible:Boolean;// = true
        private var _momId:String;
        private var _dadId:String;

        public function BabyVO(_arg1:Object, _arg2:IEventDispatcher){
            super(_arg1, _arg2);
            this.hug(_arg1[ProtocolConstants.HUNGRY_AT]);
            this._momId = _arg1[ProtocolConstants.MOM_ID];
            this._dadId = _arg1[ProtocolConstants.DAD_ID];
            speechBubblePosition = new Point(30, -200);
        }
        public function setInitialState():void{
            this.addTicking();
            dispatch(new InfoEvent(EventConstants.SET_BABY_TREATMENT, id));
        }
        public function addTicking():void{
            dispatch(new TickingEvent(TickingEvent.ADD_TICKING, this, TimeConstants.SECOND));
        }
        public function removeTicking():void{
            dispatch(new TickingEvent(TickingEvent.REMOVE_TICKING, this));
        }
        public function get currentTreatment():ITreatment{
            return (this.firstUnfinishedTreatment);
        }
        public function get isLastTreatment():Boolean{
            var _local1:ITreatment = (this._treatments[(this._treatments.length - 1)] as ITreatment);
            return ((this.currentTreatment.id == _local1.id));
        }
        public function get treatments():Array{
            return (this._treatments);
        }
        public function set treatments(_arg1:Array):void{
            this._treatments = _arg1;
        }
        public function get hasTreatmentsFinished():Boolean{
            return (!(this.currentTreatment));
        }
        public function set huged(_arg1:Boolean):void{
            this._huged = _arg1;
        }
        public function get huged():Boolean{
            return (this._huged);
        }
        public function set clickHandler(_arg1:Function):void{
        }
        public function get clickHandler():Function{
            return (null);
        }
        public function get hasClickHandler():Boolean{
            return (false);
        }
        public function onTick(_arg1:Boolean=true, _arg2:Number=0):void{
            this._time = _arg2;
            this.handleTick();
        }
        public function get diseaseId():int{
            return (this._diseaseId);
        }
        public function set diseaseId(_arg1:int):void{
            this._diseaseId = _arg1;
        }
        public function get diseaseName():String{
            return (this._diseaseName);
        }
        public function get diseaseType():String{
            return (this._diseaseType);
        }
        public function get dismissed():Boolean{
            return (this._dismissed);
        }
        public function set dismissed(_arg1:Boolean):void{
            this._dismissed = _arg1;
        }
        public function get durationType():String{
            return (this._durationType);
        }
        public function get isNewDisease():Boolean{
            return (this._isNewDisease);
        }
        public function get lastFinalizedTreatment():ITreatment{
            return (this._lastFinalizedTreatment);
        }
        public function get petDisease():String{
            return (this._petDisease);
        }
        public function get poked():Boolean{
            return (this._poked);
        }
        public function set poked(_arg1:Boolean):void{
            this._poked = _arg1;
        }
        public function moveToNextTarget(_arg1:String):void{
            targetType = _arg1;
            checkMove();
            dispatch(new InfoEvent(EventConstants.PATIENT_SPEECH_BUBBLE_UPDATE, id));
        }
        public function moveToNextTreatment():void{
        }
        override public function showSpeechBubble(_arg1:String, _arg2:Object):void{
            if (this.speechBubbleVisible){
                super.showSpeechBubble(_arg1, _arg2);
            };
        }
        private function handleTick():void{
            this.checkSpeechbubble();
            if (!this.currentTreatment){
                this.removeTicking();
                return;
            };
            this.currentTreatment.finishedIn = (this.currentTreatment.finishedAt - this._time);
            if ((((this.currentTreatment.finishedIn <= 0)) && ((this.currentTreatment.state == GameConstants.BABY_STATE_STARTED)))){
                this.currentTreatment.state = GameConstants.BABY_STATE_FINALIZING;
                dispatch(new InfoEvent(EventConstants.FINALIZE_BABY_TREATMENT, this.id));
            };
            this._blockedIn = (this._blockedAt - this._time);
            this._isBlocked = ((this._blockedIn)<0) ? true : false;
        }
        public function checkSpeechbubble():void{
            var _local1:String;
            if (this._isBlocked){
                this.showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:SpeechBubbleConstants.ICON_BROKENHEART});
            } else {
                if (!this.currentTreatment){
                    if (((!((this.momId == null))) && (!((this.dadId == null))))){
                        this.showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:SpeechBubbleConstants.ICON_HEART_SOLVED});
                    } else {
                        this.showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:SpeechBubbleConstants.ICON_HEART});
                    };
                } else {
                    switch (this.currentTreatment.state){
                        case GameConstants.BABY_STATE_NEEDED:
                            _local1 = (("Icons_" + this.currentTreatment.needsItem) + "Bubble");
                            this.showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:_local1});
                            break;
                        case GameConstants.BABY_STATE_FINALIZED:
                            removeSpeechBubble();
                            break;
                        case GameConstants.BABY_STATE_STARTED:
                            removeSpeechBubble();
                            break;
                    };
                };
            };
        }
        public function get blockedIn():int{
            return (this._blockedIn);
        }
        public function updateCurrentTreatment(_arg1:Object):void{
            this.currentTreatment.finishedAt = _arg1[ProtocolConstants.FINISHED_AT];
            this.currentTreatment.finishedIn = _arg1[ProtocolConstants.FINISHED_IN];
            this.currentTreatment.startedAt = _arg1[ProtocolConstants.STARTED_AT];
            this.currentTreatment.state = _arg1[ProtocolConstants.STATE];
        }
        private function get firstUnfinishedTreatment():ITreatment{
            var _local1:ITreatment;
            for each (_local1 in this._treatments) {
                if (!_local1.isFinalized){
                    return (_local1);
                };
            };
            return (null);
        }
        public function get blockedAt():int{
            return (this._blockedAt);
        }
        public function set blockedAt(_arg1:int):void{
            this._blockedAt = _arg1;
        }
        public function hug(_arg1:int):void{
            this._blockedAt = _arg1;
            removeSpeechBubble();
        }
        public function set pendingHugs(_arg1:int):void{
            this._pendingHugCalls = _arg1;
        }
        public function get pendingHugs():int{
            return (this._pendingHugCalls);
        }
        public function get isBlocked():Boolean{
            return (this._isBlocked);
        }
        override public function set animationState(_arg1:String):void{
            this._animationState = _arg1;
        }
        override public function get animationState():String{
            return (this._animationState);
        }
        public function get speechBubbleVisible():Boolean{
            return (this._speechBubbleVisible);
        }
        public function set speechBubbleVisible(_arg1:Boolean):void{
            this._speechBubbleVisible = _arg1;
        }
        public function getKindergartenTreatments():Array{
            var _local2:TreatmentVO;
            var _local1:Array = [];
            for each (_local2 in this.treatments) {
                if (_local2.roomType == GameConstants.TYPE_KINDERGARTEN){
                    _local1.push(_local2);
                };
            };
            return (_local1);
        }
        public function get momId():String{
            return (this._momId);
        }
        public function get dadId():String{
            return (this._dadId);
        }
        public function set momId(_arg1:String):void{
            this._momId = _arg1;
        }
        public function set dadId(_arg1:String):void{
            this._dadId = _arg1;
        }
        override public function destroy():void{
            super.destroy();
            dispatch(new TickingEvent(TickingEvent.REMOVE_TICKING, this));
        }

    }
}//package net.wooga.pets.models.world.vos.actors 
